// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: declaration of CImplActionDuplicate.
//   $Id$


#pragma once
#include "actions.h"
class CXFormsElementDuplicate;

class CImplBind;
class CImplModel;
class CSingleNodeBindingOnDemand;

//<summary>
//	Implementation of the duplicate element specified in 
//	XForms 1.1 (no URL available yet)
//</summary>
//<remarks>
//	Keen-eyed observers will note that this class has properties corresponding to
//	Single Node Binding Attributes.  You may think this queer, and that it should
//	inherit from CImplSingleNodeBinding, however, having seen the horrific diamond 
//	inheritance problem in setvalue and message, I think it better to avoid that.
//</remarks>
#include "ImplActionWithOnDemandBindings.h"

class CImplActionDuplicate
	:public CImplActionWithOnDemandBindings
{
public:
	CImplActionDuplicate(CXFormsElementDuplicate * pXFormsElement);
	virtual ~CImplActionDuplicate(void);

	//Single Node Binding Attributes
	CComBSTR m_sRef;
	CComBSTR m_sBind;

	//Attributes specific to this element.
	CComBSTR m_sOrigin;
	CComBSTR m_sBefore;

private:
	CImplBind * m_pBind;
	CSingleNodeBindingOnDemand * m_pRefEvaluator;
	CSingleNodeBindingOnDemand * m_pOriginEvaluator;
	CSingleNodeBindingOnDemand * m_pBeforeEvaluator;

	//<summary>
	//  Resolve all bindings associated with the xf:duplicate. The bindings include 
	//  Context Parent, Model, Target Evaluator and Origin Evaluator.
	//</summary>
	virtual void ResolveBindings();

	//<summary>
	//	fetches the target parent node into which the insertion should take place.
	//</summary>	
	HRESULT GetTargetParent(IXMLDOMNode * pContext,IXMLDOMNode ** ppTargetParent);

	//<summary>
	//	fetches the node to insert into the target parent;
	//</summary>	
	HRESULT GetNodeToInsert(IXMLDOMNode * pTargetParent,IXMLDOMNode ** ppNodeToInsert);
	//<summary>
	//	fetches the node that indicates the insert location for a node.
	//</summary>
	HRESULT GetInsertLocation(IXMLDOMNode * pEvaluationContext,IXMLDOMNode ** ppNodeToInsertBefore);
	//<summary>
	//	inserts pNodeToInsert into pTargetParent before pInsertBefore, 
	//</summary>
	HRESULT insertNode(IXMLDOMNode * pTargetParent,IXMLDOMNode * pNodeToInsert,IXMLDOMNode * pInsertBefore) const;

	virtual HRESULT PerformAction();
};
